<?php
session_start ();
include '../class/MMysql.php';
$error = $user_account = $user_password = "";

if (isset ( $_POST ['agent_tel'] ) && isset ( $_POST ['agent_password'] ) ) {
    $agent_tel = $_POST ['agent_tel'];
    $agent_password = $_POST ['agent_password'];


    if ($agent_tel == "" || $agent_password == "") {
        $error = "<br><span class='error'>*user_account or user password is not null</span>";
    } else {

        $user="'".$agent_tel."'";
        $password="'".$agent_password."'";

        $mysql = new MMysql();
        $res = $mysql
            ->where(array('agent_tel'=>$user,'agent_password'=>$password,"del_flag"=>0))
            ->select('agent');
        if (count($res)<=0) {

            $error = "<br><span class='error'>account or password is wrong！</span>";
        } else {

            $_SESSION ['agent_tel'] = $agent_tel;
            $_SESSION ['agent_password'] = $agent_password;

            setcookie('agent_tel', $agent_tel, time()+60*60*24*30,"/");
            setcookie('agent_id', $res[0]['agent_id'], time()+60*60*24*30,"/");
            setcookie('agent_name', $res[0]['agent_name'], time()+60*60*24*30,"/");
//            setcookie('user_last_name', $res[0]['user_last_name'], time()+60*60*24*30,"/");
//            setcookie('user_email', $res[0]['user_email'], time()+60*60*24*30,"/");
//            setcookie('user_tel', $res[0]['user_tel'], time()+60*60*24*30,"/");

            echo "<script type=text/javascript>window.location.href='settings_page_show.php';</script>";
        }
    }
}
?>
<?php


include '../base/layout.php';
echo <<<END

    <style>
        html{
            margin: 0px;
            padding: 0px;
        }
        .admin {
            position: relative;
            font-size: 24px;
            /*color: #999999;*/
            width: 350px;
            height: 60px;
            margin: 0 auto;
            margin-top: 150px;
            color: white;
        }
        input[type='text'],input[type='password']{
            background:none;
            border-top-style: none;
            border-right-style: none;
            border-left-style: none;
            width: 350px;
            height: 34px;
            color: white;
            outline:none;
            line-height: 34px;
            font-size: 20px;
            padding: 0px;
        }
        .password{
            position: relative;
            font-size: 24px;
            width: 350px;
            height: 60px;
            margin: 0 auto;
            margin-top: 10px;
        }
        .stay{
            position: relative;
            font-size: 18px;
            width: 350px;
            height: 60px;
            color: white;
            margin: 0 auto;
            margin-top: 0px;
        }
        .btnlogin{
            position: relative;
            font-size: 18px;
            margin: 0 auto;
            margin-top: 30px;
            text-align: center;
        }
        .error{
   color: red;
}
    </style>
END;



echo <<<END
<body style="background-color: #6AAB10;">
<form method='post' action='agent_login.php'>
<div class="admin">

    <input type="text" id="agent_tel" name="agent_tel" placeholder="input Account">

</div>

<div class="password">

    <input type="password" id="agent_password" name="agent_password" placeholder="input Password">

</div>


<div class="stay">
    <input type="checkbox" name="stay">
    <span>
        Stay Logged In
    </span>
      $error
</div>
<div class="btnlogin">
   <input type="submit" id="btnlogin" value="Sign in" class="btn" style="background-color:#FFFFFF;width: 150px;"  />
       
</div>

</form>
</body>
</html>
END;
?>
<script>
    $(function(){
//    $("#btnlogin").click(function(){
//       var user_account=  $("#user_account").val();
//       var user_password=  $("#user_password").val();
//
//        $.ajax( {
//            url: '../class/admin/adminfunction.php',
//            data:{
//                method:'get',
//                user_account : user_account,
//                user_password : user_password
//            },
//            type:'post',
//            success:function(data) {
//
//                if(data==1){
//
//                    window.location.href="settings_page_show.php";
//
//                }
//                else {
//                    alert('account or password is wrong')
//                }
//            },
//            beforeSend: function(){
//                //$('#warning').text('正在处理，请稍等！');
//            },
//            error : function() {
//                // view("异常！");
//                alert("fail");
//            }
//        });
//
//    });
    })
</script>



